#!/bin/sh

dirname=`dirname $0`

case $dirname in
	/*)
		cd $dirname/../.. > /dev/null
		path=`pwd`
		cd - > /dev/null
	;;
	*)
		cd `pwd`/$dirname/../.. > /dev/null
		path=`pwd`
		cd - > /dev/null
	;;
esac

echo $path

export PYTHONPATH=$path/lib

if [ "$INTERPRETER" != "" ]
then
	INTERPRETER=`which $INTERPRETER`
fi

PYPY=`which pypy-disabled 2>/dev/null`
PYTHON27=`which python2.7 2>/dev/null`
PYTHON26=`which python2.6 2>/dev/null`
PYTHON25=`which python2.5 2>/dev/null`
PYTHON24=`which python2.4 2>/dev/null`
PYTHON2=`which python2 2>/dev/null`
PYTHON=`which python 2>/dev/null`

if [ -f "$PYPY" ]
then
	INTERPRETER=$PYPY
elif [ -f "$PYTHON27" ]
then
	INTERPRETER=$PYTHON27
elif [ -f "$PYTHON26" ]
then
	INTERPRETER=$PYTHON26
elif [ -f "$PYTHON25" ]
then
	INTERPRETER=$PYTHON25
elif [ -f "$PYTHON24" ]
then
	INTERPRETER=$PYTHON24
elif [ -f "$PYTHON2" ]
then
	INTERPRETER=$PYTHON2
elif [ -f "$PYTHON" ]
then
	INTERPRETER=$PYTHON
else
	INTERPRETER=python
fi

exec $INTERPRETER $*
